package ldh.common.testui.vo;

import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken;
import ldh.common.testui.model.ParamModel;
import ldh.common.testui.util.DataUtil;
import ldh.common.testui.util.JsonUtil;
import lombok.Data;

import java.util.Map;

/**
 * Created by ldh on 2018/3/28.
 */
@Data
public class SqlCheckData {

    @Expose
    private Integer id;
    @Expose
    private Integer sqlCheckId;
    @Expose
    private String content;
    @Expose
    private Integer index;

    private Map<String, SqlColumnData> dataMap;

    public Map<String, SqlColumnData> toSqlColumnDataMap() {
        Map<String, SqlColumnData> dataMap = JsonUtil.toObject(content, new TypeToken<Map<String, SqlColumnData>>(){}.getType());
        dataMap.entrySet().stream().forEach(entry->{
            entry.getValue().setId(this.getId());
            entry.getValue().setIndex(index);
        });
        return dataMap;
    }

    public Map<String, SqlColumnData> getDataMap() {
        if (dataMap != null) return dataMap;
        if (content != null) {
            dataMap = toSqlColumnDataMap();
        }
        return dataMap;
    }

}
